package cn.tedu.charging.order.controller;


import cn.tedu.charging.common.pojo.JsonResult;
import cn.tedu.charging.order.pojo.Param.OrderCreateParam;
import cn.tedu.charging.order.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/order")
@Api(tags = "订单管理")
public class OrderController {
    @Autowired
    private OrderService orderService;
    @ApiOperation(value = "创建订单")
    @PostMapping("/create")
    public JsonResult createOrder(@RequestBody OrderCreateParam orderCreateParam){
        log.debug("创建订单-入参");
        //创建类型的接口是否需要返回出参? 要根据业务来决定
        //业务要求用户创建订单，需要跳转订单详情页
        //创建订单接口的出参 应该返回订单号
        //订单号可以作为订单详情页的入参
        log.debug("创建订单-orderService:入参：{}",orderCreateParam);
        String orderNo = orderService.createOrder(orderCreateParam);
        log.debug("创建订单-orderService:入参:{},出参:{}",orderCreateParam,orderNo);
        JsonResult<String> result = new JsonResult<>();
        result.setData(orderNo);
        result.setCode(2000);//2000代表成功
        result.setMessage("创建订单成功");//一般在错误的时候返回
        log.debug("创建订单-入参{}，出参:{}",orderCreateParam,result);
        return result;
    }
}
